<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>倒计时</title>
    <style>
        .boss{
            width: auto;
            margin: 0 auto;
            display: flex;
            justify-content: center;
        }
        .box{
            width: 100px;
            height: 50px;
            margin:  0 10px;
            text-align: center;
            font-size: 20px;
            line-height: 50px;
            background-color: blanchedalmond;
            color: red;
            font-weight: bold;
        }
        .name{
            width: 150px;
            height: 50px;
            margin:  0 10px;
            text-align: center;
            font-size: 20px;
            line-height: 50px;
            background-color: gainsboro;
            color: blue;
            font-weight: bold;
        }
        h1{
            margin: 0;
            height: 50px;
            line-height: 50px;
        }
    </style>
</head>
<body>
    <div class="boss">
        <div class="name">
            活动倒计时：
        </div>
        <div class="box"></div>
        <h1>:</h1>
        <div class="box"></div>
        <h1>:</h1>
        <div class="box"></div>
        <h1>:</h1>
        <div class="box"></div>
        <h1>:</h1>
        <div class="box"></div>
    </div>
    <script>
        var box = document.getElementsByClassName("box");
        var timego = new Date('2020 10-20 20:00:00');// 设定一个新的时间
        // console.log(timego);

        var coun_times = setInterval(function(){
            var localtime = new Date();// 当前时间
            var times = timego - localtime;// 总毫秒数

            var hao = (times % 1000);// 当前毫秒数
            var sec = parseInt(times / 1000);// 总秒数
            var sescth = (sec % 60);// 当前秒数
            var min = parseInt((sec / 60)) % 60;// 当前分钟数
            var hour = parseInt((sec / 3600)) % 24;// 小时
            var days = parseInt((sec / 86400)) % 365;// 天
            box[0].innerHTML = days + "天";
            box[1].innerHTML = hour + "时";
            box[2].innerHTML = min + "分";
            box[3].innerHTML = sescth + "秒";

            var res = '';
            if(hao < 10){
                res = '00' + hao;
            }else if(hao >= 10 && hao < 100){
                res = '0' + hao;
            }else{
                res = hao;
            }
            box[4].innerHTML = res + "毫秒";
        },1)
    </script>
</body>
</html>